package com.wngbms.shard.init;

import com.alibaba.fastjson.JSON;
import com.wngbms.shard.bean.MyUser;
import com.wngbms.shard.mapper.UserMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Slf4j
@Component
public class Cl implements CommandLineRunner, ApplicationRunner {

    @Autowired
    UserMapper userMapper;

    @Override
    public void run(String... args) throws Exception {
        List<MyUser> myUsers = userMapper.selectAll();
        log.info(JSON.toJSONString(myUsers));

        log.info("stack trace:{}", Stream.of(Thread.currentThread().getStackTrace()).map(StackTraceElement::getMethodName).collect(Collectors.toList()));
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        List<MyUser> myUsers = userMapper.findAll();
        log.info(JSON.toJSONString(myUsers));
    }
}
